<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>填报数据还原</span>
      </div>

      <el-form
        :inline="true"
        ref="queryForm"
        :model="queryParams"
        label-width="68px"
      >
        <el-form-item label="提报编号" prop="fillId">
          <el-input
            v-model="queryParams.fillId"
            placeholder="请输入提报编号"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="提报人" prop="nickName">
          <el-input
            v-model="queryParams.nickName"
            placeholder="请输入人员"
            clearable
            size="small"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="resList" stripe>
        <el-table-column
          label="填报编号"
          align="center"
          width="80"
          prop="fillId"
        />

        <el-table-column
          label="清除人员"
          align="center"
          width="80"
          prop="clearBy"
        />
        <el-table-column
          label="清除描述"
          width="80"
          prop="clearDescription"
          show-overflow-tooltip
        />
        <el-table-column
          label="还原状态"
          align="center"
          width="80"
          prop="isRestore"
        >
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.isRestore === '0' ? 'primary' : 'success'"
              disable-transitions
              >{{ scope.row.isRestore === '0' ? '未还原' : '已还原' }}</el-tag
            >
          </template>
        </el-table-column>

        <el-table-column
          label="提报日期"
          align="center"
          prop="workTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.workTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="提报人" prop="nickName" />
        <el-table-column label="部门" width="120" prop="deptName" />
        <el-table-column
          label="项目代码"
          width="150"
          prop="projectCode"
          show-overflow-tooltip
        />
        <el-table-column label="开发阶段" prop="stageName" />
        <el-table-column label="事务种类" width="230" prop="officeName" />
        <el-table-column
          label="提报工时(H)"
          width="120"
          align="center"
          prop="workHour"
        />
        <el-table-column
          label="描述"
          prop="workRemark"
          width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="回退描述"
          prop="rollback"
          width="120"
          show-overflow-tooltip
        />
        <el-table-column label="审核人" prop="checkBy" />
        <el-table-column label="状态" align="center" prop="state">
          <template slot-scope="scope">
            <el-tag
              :type="
                scope.row.state === '已审核'
                  ? 'primary'
                  : scope.row.state === '未审核'
                  ? 'info'
                  : scope.row.state === '回退'
                  ? 'warning'
                  : 'danger'
              "
              disable-transitions
              >{{ scope.row.state }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              v-hasPermi="['work:restore:list']"
              @click="handleRestore(scope.row)"
              :disabled="scope.row.isRestore === '1'"
              >数据还原</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { delList, edit } from '@/api/work/clear'

export default {
  name: 'Restore',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fillId: '',
        nickName: ''
      },
      // 数据列表
      resList: [],
      // 总条数
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 初始化 */
    getList() {
      this.loading = true
      delList(this.queryParams).then((response) => {
        this.resList = response.data.rows
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        fillId: '',
        nickName: ''
      }
      this.handleQuery()
    },
    /** 按钮操作 */
    handleRestore(row) {
      const fillId = row.fillId
      this.$modal
        .confirm('是否确认还原填报编号"' + fillId + '"的数据项？')
        .then(function () {
          return edit(row)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('还原成功')
        })
        .catch(() => {})
    }
  }
}
</script>
